package com.zhiche.lisa.lspm.service.msg.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.core.utils.HttpClientUtil;
import com.zhiche.lisa.lspm.dao.model.driver.bo.DriverLineBO;
import com.zhiche.lisa.lspm.dto.DriverTypeDTO;
import com.zhiche.lisa.lspm.service.msg.SendMsgService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: suohao
 * Date: 2019/5/30
 */
@Service
public class SendMsgServiceImpl implements SendMsgService {

    @Override
    public String sendMsg(Map<String,Object> condtion) {
        String reason = condtion.get("reason").toString();
        String content = condtion.get("content").toString();
        String mobile = condtion.get("mobile").toString();
        return this.tplSendMsg(reason,content,mobile);
    }


    public String tplSendMsg(String reason,String content,String mobile) {
        String responseText="";
        if (mobile!=null && !"".equals(mobile)){
            Map<String, String> params = new HashMap<>();
            params.put("apikey", "2ac15041e43d472237ff9ea879267a08");
            params.put("mobile",mobile);
            params.put("tpl_id", "2905330");

            try {
                String tpl_value = URLEncoder.encode("#reason#","UTF-8")+ "="
                        + URLEncoder.encode(reason,"UTF-8")+"&"+ URLEncoder.encode("#content#","UTF-8")+"="+URLEncoder.encode(content,"UTF-8");
                params.put("tpl_value",tpl_value);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            responseText=HttpClientUtil.post("https://sms.yunpian.com/v2/sms/tpl_batch_send.json", params,30000);
            return responseText;
        }
        return responseText;
    }

}
